/**
 * vue.config.js
 * https://cli.vuejs.org/zh/config/
 */
const isProduction = process.env.NODE_ENV === 'production'
const Version = new Date().getTime()

module.exports = {
  publicPath: './',
  assetsDir: `medbox_static/${Version}/`,
  // 不生成map文件
  productionSourceMap: !isProduction,
  // 文件名称不带hash值
  filenameHashing: false,
  devServer: {
    port: 9000,
    proxy: {
      // 本地调试转发
      '/api': {
        target: 'https://127.0.0.1:443',
        // target: "https://www.coderutil.com",
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          '^/api': '/api'
        },
        logLevel: 'debug' // 用于检查代理的真实地址
      }
    }
  },
  css: {
    sourceMap: !isProduction // css sourceMap 配置
  },

  chainWebpack: (config) => {
    if (process.env.use_analyzer) {
      // eslint-disable-next-line @typescript-eslint/no-var-requires
      config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
    }
  },
  configureWebpack: {
    externals: {
      vue: 'Vue',
      'vue-router': 'VueRouter',
      'element-plus': 'ElementPlus',
      dayjs: 'dayjs',
      axios: 'axios'
    }
  },
  // 多页面
  pages: {
    index: {
      entry: 'src/pages/index.ts',
      title: 'MedBox学术导航-专业、准确、及时和全面的科研与学术资源导航平台',
      template: 'public/index.html',
      cdn: {
        css: ['//unpkg.com/element-plus/dist/index.css'],
        js: [
          '//unpkg.com/vue@next',
          '//unpkg.com/element-plus',
          '//unpkg.com/@element-plus/icons-vue',
          'https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js',
          'https://cdn.jsdelivr.net/npm/axios@0.27.2/dist/axios.min.js'
        ]
      }
    },
    login: {
      entry: 'src/pages/login.ts',
      title: 'MedBox学术导航-专业、准确、及时和全面的科研与学术资源导航平台',
      template: 'public/index.html',
      cdn: {
        css: ['//unpkg.com/element-plus/dist/index.css'],
        js: [
          '//unpkg.com/vue@next',
          '//unpkg.com/element-plus',
          '//unpkg.com/@element-plus/icons-vue',
          'https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js',
          'https://cdn.jsdelivr.net/npm/axios@0.27.2/dist/axios.min.js'
        ]
      }
    },
    error: {
      entry: 'src/pages/error.ts',
      title: 'MedBox学术导航-专业、准确、及时和全面的科研与学术资源导航平台',
      template: 'public/error.html',
      cdn: {
        css: ['//unpkg.com/element-plus/dist/index.css'],
        js: [
          '//unpkg.com/vue@next',
          '//unpkg.com/element-plus',
          '//unpkg.com/@element-plus/icons-vue',
          'https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js',
          'https://cdn.jsdelivr.net/npm/axios@0.27.2/dist/axios.min.js'
        ]
      }
    },
    dictionary: {
      entry: 'src/pages/dictionary.ts',
      title: 'MedBox学术字典-专业、准确、及时和全面的科研与学术资源导航平台',
      template: 'public/index.html',
      cdn: {
        css: ['//unpkg.com/element-plus/dist/index.css'],
        js: [
          '//unpkg.com/vue@next',
          '//unpkg.com/element-plus',
          '//unpkg.com/@element-plus/icons-vue',
          'https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js',
          'https://cdn.jsdelivr.net/npm/axios@0.27.2/dist/axios.min.js'
        ]
      }
    },
    word: {
      entry: 'src/pages/word.ts',
      title: '单词',
      template: 'public/index.html',
      cdn: {
        css: ['//unpkg.com/element-plus/dist/index.css'],
        js: [
          '//unpkg.com/vue@next',
          '//unpkg.com/element-plus',
          '//unpkg.com/@element-plus/icons-vue',
          'https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js',
          'https://cdn.jsdelivr.net/npm/axios@0.27.2/dist/axios.min.js'
        ]
      }
    },
    manager: {
      entry: 'src/pages/manager.ts',
      title: '管理',
      template: 'public/index.html',
      cdn: {
        css: ['//unpkg.com/element-plus/dist/index.css'],
        js: [
          '//unpkg.com/vue@next',
          '//unpkg.com/element-plus',
          '//unpkg.com/@element-plus/icons-vue',
          'https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js',
          'https://cdn.jsdelivr.net/npm/axios@0.27.2/dist/axios.min.js'
        ]
      }
    }
  }
}
